<?php

class Staff_info extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Staff_info':
	 * @var integer $id
	 * @var string $name
	 * @var integer $sex
	 * @var string $birthday
	 * @var string $educational_background
	 * @var string $household_register
	 * @var string $card_id
	 * @var string $home_tel
	 * @var string $department
	 * @var string $position
	 * @var string $office
	 * @var string $entry_time
	 * @var string $mobile_no
	 * @var string $home_addr
	 * @var integer $state
	 * @var string $create_time
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'staff_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('name','length','min'=>2,'max'=>8),
			array('educational_background','length','min'=>2,'max'=>10),
			array('household_register','length','min'=>2,'max'=>8),
			array('card_id','length','max'=>18),
			array('home_tel','length','min'=>8,'max'=>16),
			array('department','length','max'=>80),
			array('position','length','max'=>20),
			array('office','length','max'=>80),
			array('mobile_no','length','min'=>11,'max'=>12),
			array('home_addr','length','max'=>80),
			array('sex, state', 'numerical', 'integerOnly'=>true),
			array('name,sex,birthday,educational_background,household_register,card_id,
					department,position,office,entry_time,state,create_time', 'required'),
			array('card_id', 'match' ,'pattern' => '/(^\d{15}$)|(\d{17}(?:\d|x|X)$)/'),
			array('home_tel,mobile_no', 'match' ,'pattern' => '/^[0-9 \+ -]+$/'),
			array('birthday,entry_time', 'type','type'=>'date','message'=>'{attribute} 必须为日期型(年-月-日)'), 
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'name' => '姓名',
			'sex' => '性别',
			'birthday' => '出生日期',
			'educational_background' => '学历',
			'household_register' => '户籍',
			'card_id' => '身份证	',
			'home_tel' => '住宅电话',
			'department' => '所属部门',
			'position' => '岗位',
			'office' => '所属办事处',
			'entry_time' => '入职时间',
			'mobile_no' => '手机',
			'home_addr' => '家庭地址',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
}